﻿<%@ Page Language="C#" AutoEventWireup="true" Inherits="NetUI_GoogleMap" CodeFile="GoogleMap.aspx.cs" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head id="Head1" runat="server">
    <title></title>
    <link href="../css/Public.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .MarkerText
        {
            width: 120px;
            color: blue;
            font-size: 9pt;
            font-family: Arial;
        }
        .ToolStrip
        {
            position: absolute;
            top: 0px;
            left: 0px;
            height: 30px;
            background-color: #f5f5f5;
            border-bottom: 1px solid #cccccc;
            overflow:hidden;
        }
        .ToolStrip table
        {
            height: 30px;
            margin-right:0;
            margin-left:auto;
        }
        .ToolStrip a{cursor: pointer; color: Blue; font-size:9pt;}
        .ToolStrip span{font-size:9pt;}
        .ToolStrip td
        {
            text-align: center;
            vertical-align: middle;
            padding-left: 5px;
            padding-right: 5px;
            font-size:9pt;
        }
        .ToolStrip img
        {
            text-align: center;
            vertical-align: middle;
            border: none;
        }
        #tdButton input
        {
            width: 60px;
            height: 20px;
            border: solid 2px #666666;
            background-color: White;
            font-size: 9pt;
            margin:auto;
        }
    </style>
</head>
<body style="margin-top: 0; margin-left: 0; margin-right: 0; margin-bottom: 0; overflow: hidden;"
    scroll="no" onload="initialize()" onunload="GUnload()">
    <form id="form1" runat="server">
    <div id="divContent">
        <div id="map_canvas" style="width: 100%; height: 494px;">
        </div>
        <div id="divFetching" style="color: blue; border: solid 1px #666666; position: absolute;
            width: 180px; padding-top: 3px; padding-bottom: 3px; text-align: center; display: none;
            background-color: White; left: 10px; top: 10px;">
            <%=this.GetLocalResource("Fetching")%>...
        </div>
    </div>
    <div class="ToolStrip" id="divToolStrip">
        <table cellpadding="0" cellspacing="0">
            <tr>
                <td>
                    <a onclick="map.zoomIn()"><img src="../images/zoomin.png" alt="" style="margin-right: 3px;" /><%=this.GetGlobalResource("ZoomIn")%></a>
                </td>
                <td>
                    <a onclick="map.zoomOut()"><img src="../images/zoomout.png" alt="" style="margin-right: 3px;" /><%=this.GetGlobalResource("ZoomOut")%></a>
                </td>
                <td style='<%=Session["VehicleLogin"] == null?"": "display:none;"%>'>
                    <a id="aDrawArea">
                        <img src="../images/RECT_DY.ico" alt="" style="margin-right: 3px;" /><span id="spanDA"><%=this.GetLocalResource("DrawArea")%></span></a>
                </td>
                <td style='<%=Session["VehicleLogin"] == null?"": "display:none;"%>'>
                    <a onclick="BeginPointDef()">
                        <img src="../images/POSTION_DY.ico" alt="" style="margin-right: 3px;" /><%=this.GetLocalResource("DefinePoint")%></a>
                </td>
                <td>
                    <a onclick="ToggleTraffic()">
                        <img src="../images/ROUTECASE.png" alt="" style="margin-right: 3px;" /><span id="spanTraffic"><%=this.GetGlobalResource("ShowTraffic")%></span></a>
                </td>
                <td style='<%=Session["VehicleLogin"] == null?"": "display:none;"%>'>
                    <a onclick="SetDefaultView()">
                        <img src="../images/VIEW_DY.png" alt="" style="margin-right: 3px;" /><%=this.GetLocalResource("DefaultView")%></a>
                </td>
                <td style='<%=Session["VehicleLogin"] == null?"": "display:none;"%>'>
                    <select id="ddlPoint" style="width: 80px; font-size: 9pt;"
                        onchange="RedirectTo()"><option value="">
                            <%=this.GetLocalResource("JumpTo")%></option>
                    </select>
                </td>
                <td id="tdButton" style="padding-right:5px; padding-left:auto; width:auto;display:none;">
                    <input type="button" value='<%=this.GetGlobalResource("Map")%>' title="Map" onclick="SwitchMapType(this)" /><input type="button"
                        value='<%=this.GetGlobalResource("Satellite")%>' title="Satellite" onclick="SwitchMapType(this)" /><input type="button" value='<%=this.GetGlobalResource("Hybrid")%>' title="Hybrid" onclick="SwitchMapType(this)" />
                </td>
            </tr>
        </table>
    </div>
    <script src="../js/IsInHongKong.js" type="text/javascript"></script>

    <script src="../js/GoogleMap/MapIconMaker.js" type="text/javascript"></script>

    <script src="../js/GoogleMap/labeledmarker.js" type="text/javascript"></script>

    <script src="../js/GoogleMap/Ruler.js" type="text/javascript"></script>
    <script type="text/javascript"> 
        
        var customIcons = [];
        var imgs=new Array("vehicle0.png","vehicle0_45.png","vehicle45.png","vehicle45_90.png","vehicle90.png","vehicle90_135.png","vehicle135.png"
            ,"vehicle135_180.png","vehicle180.png","vehicle180_225.png","vehicle225.png","vehicle225_270.png","vehicle270.png","vehicle270_315.png"
            ,"vehicle315.png","vehicle315_350.png");
        var VehFolders=('<%=GetFolderNames() %>').split('|');
        for(var fi=0;fi<VehFolders.length;fi++)
        {     
            if(VehFolders[fi].toLocaleLowerCase()=="person")
                continue;
            for(var i=0;i<imgs.length;i++)
            {
                var icon=new GIcon();
                icon.image="../images/veh/"+VehFolders[fi]+"/"+imgs[i];
                //icon.iconSize=new GSize(35,35);
                icon.iconAnchor = new GPoint(17, 17);
                icon.infoWindowAnchor = new GPoint(5, 1);
                customIcons[VehFolders[fi]+"_"+imgs[i].replace(".png","")]=icon;
            }
        }     
        
        var iconp=new GIcon();
        iconp.image="../images/veh/person/Person.png";
        iconp.iconSize=new GSize(30,31);
        iconp.iconAnchor = new GPoint(16, 16);
        iconp.infoWindowAnchor = new GPoint(5, 1);
        customIcons["person"]=iconp; 
        
        function GetVehIcon(Folder,Angle)
        {
            if(Folder=="person")
                return customIcons["person"];
                
            if (Angle > 350 || Angle < 10)
                return customIcons[Folder+'_vehicle0'];
            if (Angle >= 10 && Angle <= 35)
                return customIcons[Folder+'_vehicle0_45'];
            if (Angle > 35 && Angle < 55)
                return customIcons[Folder+'_vehicle45'];
            if (Angle >= 55 && Angle <= 80)
                return customIcons[Folder+'_vehicle45_90'];
            if (Angle > 80 && Angle < 100)
                return customIcons[Folder+'_vehicle90'];
            if (Angle >= 100 && Angle <= 125)
                return customIcons[Folder+'_vehicle90_135'];
            if (Angle > 125 && Angle < 145)
                return customIcons[Folder+'_vehicle135'];
            if (Angle >= 145 && Angle <= 170)
                return customIcons[Folder+'_vehicle135_180'];
            if (Angle > 170 && Angle < 190)
                return customIcons[Folder+'_vehicle180'];
            if (Angle >= 190 && Angle <= 215)
                return customIcons[Folder+'_vehicle180_225'];
            if (Angle > 215 && Angle < 235)
                return customIcons[Folder+'_vehicle225'];
            if (Angle >= 235 && Angle <= 260)
                return customIcons[Folder+'_vehicle225_270'];
            if (Angle > 260 && Angle < 280)
                return customIcons[Folder+'_vehicle270'];
            if (Angle >= 280 && Angle <= 305)
                return customIcons[Folder+'_vehicle270_315'];
            if (Angle > 305 && Angle < 325)
                return customIcons[Folder+'_vehicle315'];	
            if (Angle >= 325 && Angle <= 350)
                return customIcons[Folder+'_vehicle315_350']; 
            return customIcons[Folder+'_vehicle0'];    
        }
        
        function initialize() 
        {
            if (GBrowserIsCompatible()) 
            {
                var mapOptions = {googleBarOptions : {style : "new"}};
                map = new GMap2(document.getElementById("map_canvas"),mapOptions);
                map.enableScrollWheelZoom();
                map.enableGoogleBar();
                var coord=('<%=Common.GetAppConfigValue("DefaultPoint") %>').split(',');
                var x=parseFloat(coord[0]);
                var y=parseFloat(coord[1]);
                map.setCenter(new GLatLng(y,x), 6); 
                var gposition=new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,35));                 
                map.addControl(new GMapTypeControl(),gposition);
                var mposition=new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,60)); 
                map.addControl(new GLargeMapControl(),mposition); 
                //map.addControl(new google.maps.LocalSearch(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(140,20))); 
           
                var rposition=new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(214,35)); 
                //map.addControl(new GRulerControl(),rposition);//测距控件
                MapResize();

                var overview=new GOverviewMapControl();
                map.addControl(overview);
                geocoder = new GClientGeocoder();
                
                var trafficOptions = {"incidents":"true"};//路况信息
                trafficInfo = new GTrafficOverlay(trafficOptions);
                
                //加载所有已定义的兴趣点到地图
                NetUI_GoogleMap.GetMyPoi(LoadPoisBack)
                
                //加载用户的默认视图设置
                NetUI_GoogleMap.GetUserConfig(function(response){
                    if(response&&response.value)
                    {
                        try{
                        if(response.value=="")
                            return;
                        var args=eval("("+response.value+")");
                        if(args.MapType=="Map")
                            map.setCenter(new GLatLng(args.Latitude,args.Longitude),args.Zoom,G_NORMAL_MAP);
                        else if(args.MapType=="Satellite")
                            map.setCenter(new GLatLng(args.Latitude,args.Longitude),args.Zoom,G_SATELLITE_MAP);
                        else if(args.MapType=="Hybrid")
                            map.setCenter(new GLatLng(args.Latitude,args.Longitude),args.Zoom,G_HYBRID_MAP);
                        }catch(e){}
                    }
                });
            }
        }
        
        var btns=document.getElementById("tdButton").getElementsByTagName("input");
        function SwitchMapType(obj)
        {
            if(obj.title=="Map")
                map.setCenter(map.getCenter(),map.getZoom(),G_NORMAL_MAP);
            else if(obj.title=="Satellite")
                map.setCenter(map.getCenter(),map.getZoom(),G_SATELLITE_MAP);
            else if(obj.title=="Hybrid")
                map.setCenter(map.getCenter(),map.getZoom(),G_HYBRID_MAP);
            for(var i=0;i<btns.length;i++)
            {
                if(btns[i].title==obj.title)
                    btns[i].setAttribute("disabled","disabled");
                else
                    btns[i].removeAttribute("disabled");
            }
        }

        //显示或隐藏路况
        function ToggleTraffic() 
        {
            if (toggleState == 1) 
            {
                map.removeOverlay(trafficInfo);
                document.getElementById("spanTraffic").innerHTML='<%=this.GetGlobalResource("ShowTraffic")%>';
                toggleState = 0;
            } 
            else 
            {
                map.addOverlay(trafficInfo);
                document.getElementById("spanTraffic").innerHTML='<%=this.GetGlobalResource("HideTraffic")%>';
                toggleState = 1;
            }
        }
        
        var spanVehNoF=window.top.document.getElementById("spanVehNoF");
        var spanSystemNo=window.top.document.getElementById("spanSystemNo");             
        var spanTime=window.top.document.getElementById("spanTime");
        var spanSpeed=window.top.document.getElementById("spanSpeed");
        var spanTemperature=window.top.document.getElementById("spanTemperature");
        var spanMile=window.top.document.getElementById("spanMile");
        var spanOil=window.top.document.getElementById("spanOil");             
        var spanAcc=window.top.document.getElementById("spanAcc");
        var spanLocate=window.top.document.getElementById("spanLocate");
        var spanStatusA=window.top.document.getElementById("spanStatusA");
        var spanStatusB=window.top.document.getElementById("spanStatusB");
        var spanStatusC=window.top.document.getElementById("spanStatusC");
        var spanStatusD=window.top.document.getElementById("spanStatusD");
        var spanVoltage=window.top.document.getElementById("spanVoltage");
        var spanOM=window.top.document.getElementById("spanOM");
        var spanDayMile=window.top.document.getElementById("spanDayMile"); 
        var spanAddress=window.top.document.getElementById("spanAddress");
        
        var lblStatusA=window.top.document.getElementById("lblStatusA");
        var lblStatusB=window.top.document.getElementById("lblStatusB");
        var lblStatusC=window.top.document.getElementById("lblStatusC");
        var lblStatusD=window.top.document.getElementById("lblStatusD");

        function Clear()
        {          
            aSystemNo="";
            ClearTrack();
                                 
            spanVehNoF.innerHTML="";
            spanSystemNo.innerHTML="";
                         
            spanTime.innerHTML="";
            spanSpeed.innerHTML="";
            spanTemperature.innerHTML="";
            spanMile.innerHTML="";
            spanOil.innerHTML="";
                         
            spanAcc.innerHTML="";
            spanLocate.innerHTML="";
            spanStatusA.innerHTML="";
            spanStatusB.innerHTML="";
            spanStatusC.innerHTML="";
            spanStatusD.innerHTML="";
            
            spanVoltage.innerHTML="";
            spanOM.innerHTML="";
            spanDayMile.innerHTML=""; 
            spanAddress.innerHTML="";
        }
        function ClearTrack()
        {
            //清除历史轨迹线
            for(var i=0;i<Lines.length;i++)
            {
                if(Lines[i])
                    map.removeOverlay(Lines[i]);
            }
            Lines=[];
        }
        
        var map;
        var trafficInfo;//路况信息对象
        var toggleState = 0;//路况显示状态        
        var geocoder;//经纬度解析器
        var address;
        
        //所有跟踪车辆的当前点
        var CurrentMark=[];        
        //当前画轨迹的车辆相关记录
        var aSystemNo="";//车辆系统编号
        var chbDrawLine=window.top.document.getElementById("chbDrawLine");
        var Lines=[];//已绘制的轨迹线列表
        
        //采用如下JSON格式记录跟踪车辆列表，每项包括：车辆系统编号、车辆基本信息、上次车辆位置信息
        //{SystemNo:''
        //,ref:{VehNoF:'',VehNoS:'',VehicleType:'',OilMin:'',OilMax:'',Moil:'',OilFlag:'',FromMile:''}
        //,msg:{DateTime:'',Longitude:'',Latitude:'',Velocity:'',Temperature:'',Miles:'',Oil:'',AccStatus:'',LocateStatus:'',StatusA:'',StatusB:'',StatusC:'',StatusD:'',LevelNum:''}
        //,address:''}
        //所有正在跟踪的车辆信息，即已经加载到地图并实时更新未知的车辆
        var TrackList=[];
        
        //更新里程累加值基数
        function UpdateFromMile(SystemNo,FromMile)
        {
            if(TrackList[SystemNo])
                TrackList[SystemNo].ref.FromMile=FromMile;
        }
        
        //设定当前关注的车辆
        function LocateVehicle(SystemNo)
        {
            Clear();
            if(!LoadVeh)
                aSystemNo=SystemNo;
                
            //在跟踪列表中不存在
            if(!TrackList[SystemNo])
            {    
                NetUI_GoogleMap.GetVehicleRef(SystemNo,AddTrackVeh);
                if(!LoadVeh)
                    document.getElementById("divFetching").style.display="";
            }
            else
            {
                if(LoadVeh)
                    return;
                    
                var track=TrackList[SystemNo];
                spanVehNoF.innerHTML=track.ref.VehNoF;
                spanSystemNo.innerHTML=track.SystemNo;
                SetStatusDisp(track.ref.StatusSetting);

                var msg=track.msg;
		        if(msg)
			    {
                    var point=new GLatLng(msg.Latitude,msg.Longitude);
                    if(map.getZoom()<17)
                        map.setZoom(17);                                    
                    map.panTo(point);
                    
                    curcoord=point;
                    geocoder.getLocations(point, AfterGetAdd);
                    SetCurrentVeh(msg,track.ref,false);
                }
            }
        }
        
        //设置当前跟踪车辆的Status A,B,C,D的显示
        var status=[];
        function SetStatusDisp(StatusSetting)
        {
            if(StatusSetting)
            {
                try
                {
                    var args=StatusSetting.split('|');
                    lblStatusA.innerHTML=args[0].split(':')[0];
                    lblStatusB.innerHTML=args[1].split(':')[0];
                    lblStatusC.innerHTML=args[2].split(':')[0];
                    lblStatusD.innerHTML=args[3].split(':')[0];
                    status["StatusAON"]=args[0].split(':')[1].split('/')[0];
                    status["StatusAOFF"]=args[0].split(':')[1].split('/')[1];
                    status["StatusBON"]=args[1].split(':')[1].split('/')[0];
                    status["StatusBOFF"]=args[1].split(':')[1].split('/')[1];
                    status["StatusCON"]=args[2].split(':')[1].split('/')[0];
                    status["StatusCOFF"]=args[2].split(':')[1].split('/')[1];
                    status["StatusDON"]=args[3].split(':')[1].split('/')[0];
                    status["StatusDOFF"]=args[3].split(':')[1].split('/')[1];
                }catch(e){GetDefault();}
            }
            else
                GetDefault();
        }
        function GetDefault()
        {            
            lblStatusA.innerHTML=lblStatusA.title;
            lblStatusB.innerHTML=lblStatusB.title;
            lblStatusC.innerHTML=lblStatusC.title;
            lblStatusD.innerHTML=lblStatusD.title;
            status["StatusAON"]="ON";
            status["StatusAOFF"]="OFF";
            status["StatusBON"]="ON";
            status["StatusBOFF"]="OFF";
            status["StatusCON"]="ON";
            status["StatusCOFF"]="OFF";
            status["StatusDON"]="ON";
            status["StatusDOFF"]="OFF";
        }
        
        //添加一个监控车辆
        function AddTrackVeh(response)
        {
            if(!LoadVeh)
                document.getElementById("divFetching").style.display="none";      
            if(!response||!response.value)
                window.top.location.href="../Login.aspx";
                
            //显示基本信息
            var res=response.value.split('#');
            var VehicleInfo=res[0];
            if(!VehicleInfo)
                window.top.location.href="../Login.aspx";
            VehicleInfo=eval("("+VehicleInfo+")");
            var SystemNo=VehicleInfo.SimID;
            if(aSystemNo==SystemNo)
            {
                with(window.parent)
                {
                    spanVehNoF.innerHTML=VehicleInfo.VehNoF;
                    spanSystemNo.innerHTML=SystemNo;
                    SetStatusDisp(VehicleInfo.StatusSetting);
                }
            }
            
            //显示位置信息
            var result=res[1];            
            if(!result)
                result=null;
            else
                result=eval("("+result+")");            
            TrackList[SystemNo]={SystemNo:SystemNo,ref:VehicleInfo,msg:null,address:""};
            if(result)
            {            
                if(aSystemNo==SystemNo)
                    SetCurrentVeh(result,VehicleInfo,false);
                var point=new GLatLng(result.Latitude,result.Longitude);
                var marker = new LabeledMarker(point, {icon: GetVehIcon(VehicleInfo.VehicleType,result.Angle)
                    ,labelText: VehicleInfo.VehNoF
                        +('<%=Common.GetAppConfigValue("ShowTime")%>'=="1"?" ("+result.Velocity+"Km/h)<div>"+result.DateTime+"</div>":"")
                        +('<%=Common.GetAppConfigValue("ShowVehNoS")%>'=="1"&&VehicleInfo.VehNoS?"<div>("+VehicleInfo.VehNoS+")</div>":"")
                    ,labelClass:"MarkerText",labelOffset:new GSize(-17,17)}); 
                map.addOverlay(marker);
                //添加点击后显示标签事件
                GEvent.addListener(marker,"click",
                function(){
                    cursys=SystemNo;
                    curpoint=point;
                    geocoder.getLocations(point, OpenMapInfoWind);
                })
                               
                CurrentMark[SystemNo]=marker;            
                TrackList[SystemNo].msg=result;
                if(aSystemNo==SystemNo)
                {
                    if(map.getZoom()<17&&(!LoadVeh))
                        map.setZoom(17);                    
                    map.panTo(point);
                }
            }
            
            //继续加载下一辆车的位置到地图
            if(LoadVeh)
            {
                if(sysindex<sys.length)
                    timer=setTimeout(function(){LoadAllVeh()},10);
                else
                {
                    window.top.SetLoadVehDsp('none');
                    clearTimeout(timer);
                    LoadVeh=false;
                }
            }
        }
        
        //加载所有车辆的位置到地图
        var sys=null;
        var sysindex=0;
        var spanProgress;
        var LoadVeh=false;
        var timer=null;
        function LoadAllVeh()
        {
            if(!sys)
            {
                sys=window.top.document.getElementById("hdVehJson").value.split('|')[0].split(',');
                if(sys.length==0||(!sys[0]))
                    return;
                LoadVeh=true;
            }
                
            if(!spanProgress)
            {    
                spanProgress=window.top.document.getElementById("spanProgress");
                window.top.SetLoadVehDsp('');
            }
            LocateVehicle(sys[sysindex]);
            spanProgress.innerHTML="("+(sysindex+1).toString()+"/"+sys.length.toString()+")";
            sysindex++;
        }
        
        //停止加载车辆到地图
        function ExistLoad()
        {
            LoadVeh=false;
            window.top.SetLoadVehDsp('none');
            clearTimeout(timer);
        }
        
        //显示即时点
        function ShowNewPosition(msg)
        {
            //已将车辆加入到跟踪列表
            if(!TrackList[msg.SimID])
                return;
                
            //车辆处于定位状态
            if(msg.LocateStatus!="Locate")
            {
                if(aSystemNo==msg.SimID)
                {
                    spanLocate.innerHTML=ExplainLocate(msg.LocateStatus);
                    spanTime.innerHTML=msg.DateTime;
                }
                return;
            }
            
            var point =new GLatLng(msg.Latitude,msg.Longitude);
            var ref=TrackList[msg.SimID].ref;
            
            //上一位置点
            var lmsg=TrackList[msg.SimID].msg;
            //已经在地图上绘制过该车辆的标注
            if(CurrentMark[msg.SimID])
            {
                if(chbDrawLine.checked)
                {
                    if(lmsg&&aSystemNo==msg.SimID)
                    {
                        var latlng = new GLatLng(lmsg.Latitude,lmsg.Longitude);
                        var polyline = new GPolyline([latlng, point], "blue", 3);
                        map.addOverlay(polyline);
                        Lines[Lines.length]=polyline;
                    }
                }
                else
                    ClearTrack();
                map.removeOverlay(CurrentMark[msg.SimID]);//移除上一个位置点
            }

            //更新车辆地图标注
            var marker = new LabeledMarker(point, {icon: GetVehIcon(ref.VehicleType,msg.Angle)
                ,labelText: ref.VehNoF
                    +('<%=Common.GetAppConfigValue("ShowTime")%>'=="1"?" ("+msg.Velocity+"Km/h)<div>"+msg.DateTime+"</div>":"")
                    +('<%=Common.GetAppConfigValue("ShowVehNoS")%>'=="1"&&ref.VehNoS?"<div>("+ref.VehNoS+")</div>":"")
                ,labelClass:"MarkerText",labelOffset:new GSize(-17,17)}); 
            map.addOverlay(marker);
            CurrentMark[msg.SimID]=marker;
            
            //添加点击后显示标签事件
            GEvent.addListener(marker,"click",
            function(){
                cursys=msg.SimID;
                curpoint=point;
                geocoder.getLocations(point, OpenMapInfoWind);
            });
            
            var IsParking=(lmsg&&lmsg.Longitude==msg.Longitude&&lmsg.Latitude==msg.Latitude);
            //设置地图中心到当前点
            if(aSystemNo==msg.SimID)
            {
                SetCurrentVeh(msg,ref,IsParking);
                map.panTo(point);
            }
            
            //更新车辆位置数据列表
            TrackList[msg.SimID].msg=msg;
        }
        
        var cursys="";
        var curpoint=null;        
        function OpenMapInfoWind(response)
        {
            if(response&&response.Status.code==200)
            {
                try
                {
                    var curmsg=TrackList[cursys].msg;
                    var curref=TrackList[cursys].ref;
                    
                    var place = response.Placemark[0];
                    var add=place.address;
                    //地址解析纠正
                    var address=ReGecoding(curmsg.Longitude,curmsg.Latitude);
                    if(address!="")
                        add=address;
                    
                    map.openInfoWindowHtml(curpoint,
                        '<b><%=this.GetLocalResource("VehNoF")%>: </b><font color=blue>' + curref.VehNoF +'</font><br>'
                        +('<%=Common.GetAppConfigValue("ShowTime")%>'=='1'?'':'<b><%=this.GetLocalResource("Time")%>:</b>'+curmsg.DateTime+'<br>')
                        +'<b><%=this.GetLocalResource("Status")%>: </b>'+(parseInt(curmsg.Velocity)<2?'<%=this.GetLocalResource("Stoped")%>':'<%=this.GetLocalResource("Running")%>...')+'<br>' 
                        +(parseInt(curmsg.Velocity)<2?'':'<b><%=this.GetLocalResource("Speed")%>: </b>'+curmsg.Velocity
                                                        +'Km/h<b style=\"margin-left:10px;\"><%=this.GetLocalResource("Angle")%>: </b>'
                                                        +ExplainAngle(curmsg.Angle)+"<br>")
                                                        +'<b><%=this.GetLocalResource("CurrentLocation")%>: </b>' + add +'<br>');
                }
                catch(e){}
            }
        }
        
        //更新当前跟踪车辆的状态
        function SetCurrentVeh(msg,ref,IsParking)
        {                
            var mile=msg.Miles/1000; 

            if('<%=Common.GetAppConfigValue("ShortTime")%>'=="1")
                msg.DateTime=msg.DateTime.substr(msg.DateTime.indexOf(' ')+1,8);
            spanTime.innerHTML=msg.DateTime;
            spanSpeed.innerHTML=msg.Velocity;
            spanTemperature.innerHTML=msg.Temperature.toString();
            spanMile.innerHTML= mile;
            
            var OilVal=0;
	        if(msg.Oil<=32767)
	        {
                if (ref.OilFlag==0)//满箱油电阻值最大
                    OilVal = parseInt((((msg.Oil - ref.OilMin) * 1.00) / (ref.OilMax - ref.OilMin)) * ref.Moil);
                else
                    OilVal = parseInt((1 - ((msg.Oil - ref.OilMin) * 1.00) / (ref.OilMax - ref.OilMin)) * ref.Moil);
	        }
            spanOil.innerHTML=parseInt(OilVal)>-1?OilVal:0; 
            spanOM.innerHTML="("+msg.Oil+"Ω)";
                         
            spanAcc.innerHTML=msg.AccStatus;
            spanLocate.innerHTML=ExplainLocate(msg.LocateStatus);
            spanStatusA.innerHTML=status["StatusA"+msg.StatusA];
            spanStatusB.innerHTML=status["StatusB"+msg.StatusB];
            spanStatusC.innerHTML=status["StatusC"+msg.StatusC];
            spanStatusD.innerHTML=status["StatusD"+msg.StatusD];
            
            spanVoltage.innerHTML=msg.LevelNum;
            var DayMileFrom=TrackList[msg.SimID].ref.FromMile;
            if(!DayMileFrom)
                DayMileFrom=parseFloat(window.top.document.getElementById("aMile"+msg.SimID.toString()).title);
            spanDayMile.innerHTML=(mile-DayMileFrom).toFixed(3);
            
            //位置有更新
            if(!IsParking)
            {
                var point =new GLatLng(msg.Latitude,msg.Longitude);
                curcoord=point;
                geocoder.getLocations(point, AfterGetAdd);
            }
        }
        
        var curcoord;
        function AfterGetAdd(response)
        {
            var add="";//alert(curcoord.lng()+","+curcoord.lat());
            if (response!=null && response.Status.code == 200) 
                add=response.Placemark[0].address;//alert(add);
            //地址解析纠正
            var address=ReGecoding(curcoord.lng(),curcoord.lat());
            if(address!="")
                add=address;//alert(add);
            spanAddress.innerHTML=add;
        }
        
    //绘制区域-------------------------------------------------------------
    var OperateType=0;//0无任何操作，1定义位置点，2定义区域
    var gevent;//地图绘制事件
    
    var DrawArea='<%=this.GetLocalResource("DrawArea")%>';
    var ClearArea='<%=this.GetLocalResource("ClearArea")%>';
    var points=[];//多边形点集合
    var polygon=null;//多边形
    var polyline=null;
    var spanDA=document.getElementById("spanDA");
    var aDrawArea=document.getElementById("aDrawArea");
    //开始绘制区域
    function BeginAreaDef()
    {
        OperateType=2;
        gevent=GEvent.addListener(map,"click",DrawPolygon);
        document.getElementById("hdStrPoints").value="";
        spanDA.innerHTML=ClearArea;
        aDrawArea.onclick=function(){EndDraw()};
    }
    aDrawArea.onclick=function(){BeginAreaDef()};
        
    function DrawPolygon(overlay,latlng)
    {
        if(OperateType!=2)
            return;
            
        if(polygon)
            map.removeOverlay(polygon);
        if(polyline)
            map.removeOverlay(polyline);
        if(!latlng)
        {
            SubmitArea()
            return;
        }
            
        var lat = latlng.lat();
        var lon = latlng.lng();
        points[points.length]=new GLatLng(lat, lon);
        if(points.length>2)
        {
            var pts=[];
            for(var i=0;i<points.length;i++)
            {
                pts[i]=points[i];
            }
            pts[pts.length]=points[0];
            polygon = new GPolygon(pts, "#f33f00", 2, 1, "#ff0000", 0.2);
            map.addOverlay(polygon);
        }
        else if(points.length==2)
        {
            polyline = new GPolyline(points, "#f33f00", 2);
            map.addOverlay(polyline);
        }
    }
    
    //退出区域绘制
    function EndDraw()
    {
        OperateType=0;        
        if(gevent)
            GEvent.removeListener(gevent);
        if(polygon)
            map.removeOverlay(polygon);
        if(polyline)
            map.removeOverlay(polyline);
        points=[];
        polygon=null;
        polyline=null;
        spanDA.innerHTML=DrawArea;
        aDrawArea.onclick=function(){BeginAreaDef()};
    }
    
    //保存区域
    function SubmitArea()
    {
        if(OperateType==2)
        {
            window.top.SaveWF();
            var hdStrPoints=document.getElementById("hdStrPoints");
            for(var i=0;i<points.length;i++)
            {
                if(hdStrPoints.value!="")
                    hdStrPoints.value+="|";
                hdStrPoints.value+=points[i].lng()+","+points[i].lat();
            }
        }
        EndDraw();
    }
    //定义位置点-----------------------------------------------------------    
    //地图上显示的自定义标注
    var PointMarkers=[];
    var ddlPoint=document.getElementById("ddlPoint");
    function BeginPointDef()
    {
        OperateType=1;
        document.getElementById("hdStrPoints").value="";
        gevent=GEvent.addListener(map,"click",DefinePoint);
    }
    function DefinePoint(overlay,latlng)
    {
        if(OperateType!=1)
            return;
        var lat = latlng.lat();
        var lon = latlng.lng();
        document.getElementById("hdStrPoints").value=lon+","+lat;
        window.top.SavePoint();
        GEvent.removeListener(gevent);
        OperateType=0;        
    }
    //添加兴趣点到地图
    function ShowPoi(mark)
    {
        var ico=new GIcon();
        ico.image=mark.ImagePath;
        ico.iconSize=new GSize(16,16);
        ico.iconAnchor = new GPoint(8, 8);
        ico.infoWindowAnchor = new GPoint(5, 1);
        var point=new GLatLng(mark.Latitude,mark.Longitude);
        var poi = new LabeledMarker(point, {icon: ico
            ,labelText: mark.PointName
            ,labelClass:"MarkerText",labelOffset:new GSize(-8,8)}); 
        map.addOverlay(poi);
        PointMarkers[mark.MpID]={Overlay:poi,Coord:point};
        GEvent.addListener(poi, "click", function(){ 
            map.openInfoWindowHtml(point, "<a href='javascript:RemovePoi(\""+mark.MpID+"\")'>"
            +'<%=this.GetLocalResource("DeletePoi")%>'+"</a>");
            setTimeout(function(){map.closeInfoWindow();},4000);
        }); 
        
        var opt=document.createElement("option");
        opt.value=mark.MpID;
        opt.text=mark.PointName;
        ddlPoint.options.add(opt);
    }
    //从地图上移除兴趣点
    function RemovePoi(id)
    {
        if(confirm('<%=this.GetLocalResource("DeleteConfirm")%>'))
            NetUI_GoogleMap.DeletePoi(id,RemovePoiBack);
        map.closeInfoWindow();
    }
    function RemovePoiBack(response)
    {
        if(response&&response.value)
        {    
            map.removeOverlay(PointMarkers[response.value].Overlay);
            for(var i=0;i<ddlPoint.options.length;i++)
            {
                if(ddlPoint.options[i].value==response.value)
                {    
                    ddlPoint.removeChild(ddlPoint.options[i]);
                    break;
                }
            }
        }
    }
    //将兴趣点设置到地图中心
    function RedirectTo()
    {
        if(ddlPoint.selectedIndex==0)
            return;
        var point=PointMarkers[ddlPoint.options[ddlPoint.selectedIndex].value].Coord;
        map.setCenter(point,16);
    }
    function LoadPoisBack(response)
    {
        if(!response||!response.value)
            return;
        var val=eval("("+response.value+")");
        var len=val.pois.length;
        for(var i=0;i<len;i++)
        {
            ShowPoi(val.pois[i]);
        }
    }
    
    //设置默认视图-----------------------------------------------------------------------
    function SetDefaultView()
    {
        var center=map.getCenter();
        var MapType="Map";
        if(map.getCurrentMapType()==G_NORMAL_MAP)
            MapType="Map";
        else if(map.getCurrentMapType()==G_SATELLITE_MAP)
            MapType="Satellite";
        else if(map.getCurrentMapType()==G_HYBRID_MAP )
            MapType="Hybrid";
        NetUI_GoogleMap.SaveUserConfig(center.lng(),center.lat(),map.getZoom(),MapType,function(response){
            if(response&&response.value)
                alert('<%=this.GetGlobalResource("OperationSuc")%>');
            else
                alert('<%=this.GetGlobalResource("OperationFail")%>');
        });
    }
    
        //辅助方法-----------------------------------------------------------------------
        function GetAddress(Longitude,Latitude,CallBackFunct)
        {
            var point =new GLatLng(Latitude,Longitude);
            geocoder.getLocations(point, CallBackFunct);
        }        
        
        function MapResize()
        {
            document.getElementById("map_canvas").style.height=document.documentElement.clientHeight+"px";
            document.getElementById("divToolStrip").style.width=document.documentElement.clientWidth+"px";
            //$("#map_canvas").css("height",$(window).height());
            //$("#divToolStrip").css("width",($(window).width()-300)+"px");
            map.checkResize();
        }
        
        //解析方向
        function ExplainAngle(Angle)
        {
            if (Angle > 350 || Angle < 10)
	            return '<%=this.GetGlobalResource("North")%>';

            if (Angle >= 10 && Angle <= 80)
	            return '<%=this.GetGlobalResource("Northeast")%>';

            if (Angle > 80 && Angle < 100)
	            return '<%=this.GetGlobalResource("East")%>';

            if (Angle >= 100 && Angle <= 170)
	            return '<%=this.GetGlobalResource("Southeast")%>';

            if (Angle > 170 && Angle < 190)
	            return '<%=this.GetGlobalResource("South")%>';

            if (Angle >= 190 && Angle <= 260)
	            return '<%=this.GetGlobalResource("Southwest")%>';

            if (Angle > 260 && Angle < 280)
	            return '<%=this.GetGlobalResource("West")%>';

            if (Angle >= 280 && Angle <= 350)
	            return '<%=this.GetGlobalResource("Northwest")%>';	 
	        return "";    
        }
    
    //定位状态解析
    function ExplainLocate(val)
    {
        switch(val)
        {
            case'NoLocate':
                return'<%=this.GetGlobalResource("NotLocate")%>';
            case'Locate':
                return'<%=this.GetGlobalResource("Locate")%>';
            case'Open':
                return'<%=this.GetGlobalResource("Open")%>';
            case'Short':
                return'<%=this.GetGlobalResource("Short")%>';
            default:
                return'';
        }
    }
    //搜索指定地点的车辆----------------------------------------------------------
    var curIndex=0;  
    var curAddress; 
    var spanSProgress=window.top.document.getElementById("spanSProgress");
    var btnSearch=window.top.document.getElementById("btnSearch");
    var rows=null; 
    function SearchByAddress()
    {
        if(curIndex==0)
        {    
            curAddress=window.top.document.getElementById("tbVehNoF").value.split(' ');
            if(curAddress.length>0&&curAddress[0]=="")
            {
                for(var i=0;i<sys.length;i++)
                    window.top.document.getElementById("tr"+sys[i]).style.display="";
                btnSearch.style.display="";
                spanSProgress.style.display="none";
                return;
            }
            else if(rows==null)
            {
                rows=[];
                for(var i=0;i<sys.length;i++)
                    rows[sys[i]]=window.top.document.getElementById("tr"+sys[i]);
            }            
            window.top.DspVehList("");
            btnSearch.style.display="none";
            spanSProgress.style.display="";
        }
        spanSProgress.innerHTML='<%=this.GetLocalResource("Searching")%>('+curIndex+'/'+sys.length+')...';
        
        var msg=(TrackList[sys[curIndex]]?TrackList[sys[curIndex]].msg:null);
        if(msg)
        {    
            var point =new GLatLng(msg.Latitude,msg.Longitude);
            geocoder.getLocations(point, SearchBack);
        }
        else
        {
            rows[sys[curIndex]].style.display="none";
            if(curIndex!=sys.length-1)
            {
                curIndex++;
                SearchByAddress();
            }
            else
            {    
                curIndex=0;
                btnSearch.style.display="";
                spanSProgress.style.display="none";
            }
        }
    }
    
    function SearchBack(response)
    {
        var disp="";
        //筛选不符合条件的行
        if(response&&response.Status.code==200)
        {
            var res=response.Placemark[0].address;
            for(var i=0;i<curAddress.length;i++)
            {
                if(curAddress[i]&&res.indexOf(curAddress[i])==-1)
                {
                    disp="none";
                    break;
                }
            }            
        }
        else
            disp="none";
        rows[sys[curIndex]].style.display=disp;
        
        if(curIndex!=sys.length-1)
        {
            curIndex++;
            setTimeout(function(){SearchByAddress()},20);
        }
        else
        {    
            curIndex=0;
            btnSearch.style.display="";
            spanSProgress.style.display="none";
        }
    }
    </script>

    <input type="hidden" id="hdStrPoints" />
<!--
    <script src="../js/ForFloatForm.js" type="text/javascript"></script>-->
    </form>
</body>
</html>
